package com.yuanchu.marketing.listener;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-02-24 1:56
 */
//注解为配置类
@Configuration
public class RabbitConfigDirect {
    //第一个队列，起名direct_queue，后面监听器里的监听注解queues属性配置队列名获取消息
    @Bean
    public Queue directQueue(){
        return new Queue("direct.queue1");
    }
    //第二个队列
    @Bean
    public Queue directQueue2(){
        return new Queue("direct.queue2");
    }
    //直连交换机，起名directExchange
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("directExchange");
    }
    //绑定直连，绑定直连队列到直连交换机，with里是routingKey路径关键词的起名
    @Bean
    public Binding bindingDirect(){
        return BindingBuilder.bind(directQueue()).to(directExchange()).with("red");
    }

    //绑定队列2到交换机，路径关键词设为"yellow"
    @Bean
    public Binding bindingDirect2(){
        return BindingBuilder.bind(directQueue2()).to(directExchange()).with("yellow");
    }
}
